{extend name="common/__base"}

{block name="body"}
<form class="layui-form layui-form-pane">
    <div class="layui-form-item">
        <label class="layui-form-label">上级菜单</label>
        <div class="layui-input-block">
            <select name="pid">
                <option value="">选择上级</option>
                {volist name="oneMenuList" id="vo"}
                <option value="{$vo.id}">{$vo.title}</option>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单名称</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="title" lay-verify="require" placeholder="菜单名称">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单地址</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="name" placeholder="菜单地址">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选择图标</label>
        <div class="layui-input-block">
            <input type="text" name="icon" id="icon_picker" lay-filter="icon_picker" style="display: none;">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="number" class="layui-input" name="sort" value="9" placeholder="排序">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">显示|隐藏</label>
        <div class="layui-input-block">
            <input type="checkbox" name="is_show" value="1" lay-skin="switch" lay-text="显示|隐藏" checked>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="submit">添加</button>
        </div>
    </div>
</form>
{/block}

{block name="js"}
<script>
    layui.use(['form', 'element', 'iconPickerFa'], function () {
        let isClick = true,
            iconPickerFa = layui.iconPickerFa,
            form = layui.form,
            $ = layui.jquery;

        // 渲染选择图标
        iconPickerFa.render({
            elem: "#icon_picker",
            url: "/static/admin/lib/font-awesome-4.7.0/less/variables.less",
            search: true,
            page: true,
            limit: 12
        });

        // 提交
        form.on("submit(submit)", function () {
            if (isClick) {
                isClick = false;
                $.post("{:url('admin/system/addMenu')}", $("form").serialize(), function (res) {
                    if (res.code == 1) {
                        layer.msg(res.msg, function () {
                            parent.location.reload();
                        });
                    } else {
                        isClick = true;
                        layer.msg(res.msg);
                    }
                }, "json");
            } else {
                layer.msg("不允许重复提交");
            }
            return false;
        });
    });
</script>
{/block}